package com.kuanter.kuanterauto.view;

import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;

/** 
 * @author utopia
 * @version 2013-10-18 下午4:09:48
 * 
 */
public class LineView extends View {
	Paint paint = new Paint();
	List<Po> listPoints;
	
	public List<Po> getListPoints() {
		return listPoints;
	}

	public void setListPoints(List<Po> listPoints) {
		this.listPoints = listPoints;
	}

	public LineView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public LineView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public LineView(Context context) {
		super(context);
	}

	@Override
	public void draw(Canvas canvas) {  //6
		if (listPoints != null) {

			paint.setColor(Color.WHITE);
			paint.setAntiAlias(true); // 锯齿不显示
			paint.setStrokeWidth(5); // 笔宽
			// paint.setStyle(Style.STROKE); //设置非填充
			/*for (int i = 0; i < listPoints.size() - 1; i++) {
				Po start = listPoints.get(i);
				Po end = listPoints.get(i + 1);
				if(start != null && end != null) {
					canvas.drawLine(start.x, start.y, end.x, end.y, paint);
				}
			}*/
			if(listPoints.size() > 1) {
				for (int i = 0; i < listPoints.size() - 1; i++) {
					Po start = listPoints.get(i);
					Po end = listPoints.get(i + 1);
					if(start != null && end != null) {
						canvas.drawLine(start.x, start.y, end.x, end.y, paint);
					}
				}
			} else {
				for (int i = 0; i < listPoints.size(); i++) {
					Po start = listPoints.get(i);
					canvas.drawCircle(start.x, start.y, 5, paint);
				}
			}
			
			/*for (int i = 0; i < listPoints.size(); i++) {
				Po start = listPoints.get(i);
				canvas.drawCircle(start.x, start.y, 5, paint);
			}*/
			
			
		}
		super.draw(canvas);
	}

	public static class Po {
		public float x;
		public float y;
	}
}
